package cn.iocoder.yudao.module.nmkj.controller.app.introduction;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.nmkj.controller.admin.introduction.vo.IntroductionPageReqVO;
import cn.iocoder.yudao.module.nmkj.controller.admin.introduction.vo.IntroductionRespVO;
import cn.iocoder.yudao.module.nmkj.dal.dataobject.introduction.IntroductionDO;
import cn.iocoder.yudao.module.nmkj.service.introduction.IntroductionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户APP - 商品介绍")
@RestController
@RequestMapping("/nmkj/introduction")
@Validated
public class AppIntroductionController {

    @Resource
    private IntroductionService introductionService;

    @GetMapping("/page")
    @Operation(summary = "获得商品介绍分页")
    public CommonResult<PageResult<IntroductionRespVO>> getIntroductionPage(@Valid IntroductionPageReqVO pageReqVO) {
        pageReqVO.setStatus(1); //用户端请求的数据必须为启用状态
        PageResult<IntroductionDO> pageResult = introductionService.getIntroductionPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, IntroductionRespVO.class));
    }

    @GetMapping("/list")
    @Operation(summary = "获得商品介绍列表")
    public CommonResult<List<IntroductionRespVO>> getIntroductionList(@Valid IntroductionPageReqVO reqVO) {
        reqVO.setStatus(1); //用户端请求的数据必须为启用状态
        List<IntroductionDO> listResult = introductionService.getIntroductionList(reqVO);
        return success(BeanUtils.toBean(listResult, IntroductionRespVO.class));
    }

}
